package com.towexin.application.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.towexin.application.system.domain.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {
	// 根据用户名获取角色(包含冻结角色)
	@Select("SELECT a.* FROM t_role a LEFT JOIN t_user_role b ON a.id=b.r_id LEFT JOIN t_user c ON b.u_id=c.id WHERE c.username=#{username}")
	Role selectByUserName(String username);

	// 根据用户名获取角色标识（包含默认角色、排除冻结角色）
	@Select("SELECT a.mark FROM t_role a LEFT JOIN t_user_role b ON a.id=b.r_id LEFT JOIN t_user c ON b.u_id=c.id WHERE c.username=#{username} AND a.`status` IS TRUE UNION ALL SELECT mark FROM t_role WHERE default_role IS TRUE AND `status` IS TRUE")
	List<String> selectMarkAndDefaultByUserName(String username);
}
